﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Localization;

namespace MvcEngine.Core.Validation
{
    /// <summary>
    /// Checks if the string value is not null or empty.
    /// </summary>
    public class RequiredFieldValidatorAttribute : FieldValidatorAttribute
    {
        public RequiredFieldValidatorAttribute(string message)
            : base(message)
        {
            ErrorMessage = Message;
        }

        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value to validate.</param>
        /// <returns>
        /// 	<c>true</c> if the specified value is valid; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsValid(object value)
        {
            if (value == null)
                return false;

            return !string.IsNullOrEmpty(value.ToString());
        }
    }
}
